
import sys
import pathlib
import importlib
import os
import re

tools = []
choice = []


def getRoot():
    pathReg = re.compile(r'MYPATH.*')
    return pathReg.sub('MYPATH', __file__)


toolList = filter(lambda x: x[0] == "_", os.listdir(getRoot() + "/__tools__"))
toolList = map(lambda x: x.split(".")[0], toolList)
toolList = filter(
    lambda x: ["__init__", "__pycache__"].count(x) == 0, toolList)
toolList = list(toolList)
"""
toolList=[
    "md5","showip","backup",
    "alarm","stopwatch","mixmp4","cutmp3","color",
    "walk","search"
]"""

toolnameRaw = pathlib.Path(__file__).absolute().parts[-1]
toolname = toolnameRaw[2:-5]


def getArgv(ind):
    _thisArgInd = sys.argv.index(toolname)
    return sys.argv[_thisArgInd+ind]


if (len(sys.argv) > 1):
    mod = importlib.import_module('__tools__.__%s__' % sys.argv[1])
    tools.append(mod.func)
    choice.append(mod.func(1))
else:
    for item in toolList:
        mod = importlib.import_module('__tools__.%s' % item)
        tools.append(mod.func)
        choice.append(mod.func(1))
